/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ttaclient;

import Helper.TTAHelper.Helper_CustomerLoyalty;
import java.util.List;
import java.util.Scanner;
import javax.ejb.EJB;
import session.TX.CustomerAnalysisSBRemote;
import session.TX.ItineraryPlannerSBRemote;

/**
 *
 * @author Lu Xiaodi
 */
public class CustAnalysis {

    @EJB
    public static CustomerAnalysisSBRemote customerAnalysisBean;
    @EJB
    public static ItineraryPlannerSBRemote itineraryPlannerBean;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Integer optionInt = 100;

        while (optionInt != 0) {
            System.out.println("1. Add new user");
            System.out.println("2. Displays all users");
            System.out.println("3. print out all local customers");
            System.out.println("4. print out all foreign customers");
            System.out.println("5. print out customer purchases");
            System.out.println("6. compute local loyalty index");
            System.out.println("7. populate outlet reservations");
            System.out.println("8. print out customer reservations");
            System.out.println("9. compute foreign loyalty index");
            System.out.println("0. Exit");
            optionInt = sc.nextInt();
            sc.nextLine();

            if (optionInt == 1) {
                System.out.print("enter user email: ");
                String email = sc.nextLine();
                System.out.print("enter country: ");
                String country = sc.nextLine();
                System.out.print("enter birth year: ");
                int year = sc.nextInt();
                itineraryPlannerBean.createUser_Test(email, country, year);
            } else if (optionInt == 2) {
                List<String> users = itineraryPlannerBean.printUser_Test();
                System.out.println();
                System.out.println("================Display all users===============");
                for (String u : users) {
                    System.out.println(u);
                }
                System.out.println("============End displaying all users============");
                System.out.println();
            } else if (optionInt == 3) {
                List<String> customers = customerAnalysisBean.getLocalCustomers_Test();
                for (String u : customers) {
                    System.out.println(u);
                }
            } else if (optionInt == 4) {
                List<String> customers = customerAnalysisBean.getForeignCustomers_Test();
                for (String u : customers) {
                    System.out.println(u);
                }
            } else if (optionInt == 5) {
                System.out.print("enter user email: ");
                String email = sc.nextLine();
                System.out.print("enter outlet id: ");
                String idStr = sc.nextLine();
                Long id = Long.parseLong(idStr.trim());
                List<String> result = customerAnalysisBean.getCustomerPurchases_Test(email, id);
                for (String s : result) {
                    System.out.println(s);
                }
            } else if (optionInt == 6) {
                System.out.print("enter outlet id: ");
                String idStr = sc.nextLine();
                Long id = Long.parseLong(idStr.trim());
                List<Helper_CustomerLoyalty> result = customerAnalysisBean.getSortedLocalLoyaltyIdx(id);
                for (Helper_CustomerLoyalty h : result) {
                    System.out.println("userId:" + h.getCustomerId() + "; loyaltyIdx:" + h.getLoyaltyIndex()
                            + "; rank:" + h.getRank());
                }
            } else if (optionInt == 7) {
                itineraryPlannerBean.populateOutletReservation();
            } else if (optionInt == 8) {
                System.out.print("enter outlet id: ");
                String idStr = sc.nextLine();
                Long oId = Long.parseLong(idStr.trim());
                System.out.print("enter cust id: ");
                idStr = sc.nextLine();
                Long cId = Long.parseLong(idStr.trim());
                List<String> result = customerAnalysisBean.getCustomerReservation_Test(cId, oId);
                System.out.println("=================Reservation by CustomerId " + cId + " for Outlet " + oId + " ===================");
                for (String s : result) {
                    System.out.println(s);
                }
                System.out.println("=================Reservation by CustomerId " + cId + " for Outlet " + oId + " ===================");
            } else if (optionInt == 9) {
                System.out.print("enter outlet id: ");
                String idStr = sc.nextLine();
                Long id = Long.parseLong(idStr.trim());
                List<Helper_CustomerLoyalty> result = customerAnalysisBean.getSortedForeignLoyaltyIdx(id);
                for (Helper_CustomerLoyalty h : result) {
                    System.out.println("userId:" + h.getCustomerId() + "; loyaltyIdx:" + h.getLoyaltyIndex()
                            + "; rank:" + h.getRank());
                }
            }
        }
    }
}
